<template>
  <div class="container">
    <div class="search-bar">
      <div class="search-box">
        <img src="../../images/icon/search.png" alt="" class="search-img" />
        <input
          type="text"
          class="sear-input"
          v-model="searchValue"
          placeholder="输入关键字搜索"
          @blur="search"
        />
      </div>
      <text class="search-hint" @click="back">取消</text>
    </div>
    <div class="search-dispaly">
      <div class="hot-search">
        <div class="title-text">热门搜索</div>
        <div class="hot-search-tags"></div>
      </div>
      <div class="history-search">
        <div class="title-text history-line">
          搜索历史
          <div class="clear-history">
            <img src="../../images/icon/clear-his.png" alt="" @click="del" />
          </div>
        </div>

        <div class="his-search-tags">
          <span
            class="tags"
            @click="search1"
            v-for="(item, i) in data"
            :key="i"
            >{{ item }}</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
      searchValue: "",
    };
  },
  methods: {
    //点击取消返回上个页面
    back() {
      uni.navigateBack();
    },
    //输入框失焦事件
    search() {
      if (this.searchValue != "") {
        this.data.push(this.searchValue);
        uni.navigateTo({
          url: `/pages/search-prod-show/index?value=${this.searchValue}`,
        });
        this.searchValue = "";
      }
    },
    search1() {
      uni.navigateTo({
        url: `/pages/search-prod-show/index?value=${this.searchValue}`,
      });
    },
    //删除历史数据
    del() {
      this.data.splice(0);
    },
  },
};
</script>

<style>
.container {
  height: 100%;
  box-sizing: border-box;
  color: #333;
  font-family: helvetica, "Heiti SC", PingFangSC-Light;
}
.search-bar {
  width: 100%;
  top: 0;
  left: 0;
  color: #777;
  background: #fff;
  box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.07);
  z-index: 3;
}
.sear-input {
    height: 60rpx;
    border-radius: 50rpx;
    border: 0;
    margin: 0 30rpx 0 64rpx;
    line-height: 48rpx;
    vertical-align: top;
    background: #f7f7f7;
    font-size: 28rpx;
}
.search-bar .search-box .search-img {
    width: 32rpx;
    height: 32rpx;
    position: absolute;
    left: 20rpx;
    top: 14rpx;
    display: block;
}
input {
    cursor: auto;
    display: block;
    height: 1.4rem;
    text-overflow: clip;
    overflow: hidden;
    white-space: nowrap;
    font-family: UICTFontTextStyleBody;
    min-height: 1.4rem;
}
.search-bar .search-box {
  position: relative;
  height: 60rpx;
  background: #f7f7f7;
  z-index: 999;
  width: 80%;
  margin-left: 70rpx;
  border-radius: 50rpx;
  margin: 20rpx 0 20rpx 20rpx;
}
.search-bar .search-box .search-img {
  width: 32rpx;
  height: 32rpx;
  position: absolute;
  left: 20rpx;
  top: 14rpx;
  display: block;
}

.search-bar .search-hint {
  font-size: 28rpx;
  position: absolute;
  right: 30rpx;
  top: 31rpx;
  color: #eb2444;
}
.search-display {
  background: #fff;
  padding: 20rpx;
  margin-top: 100rpx;
}

.search-display .title-text {
  padding: 30rpx 0;
  font-size: 30rpx;
  color: #666;
}
.hot-search {
  width: 100%;
  height: 100px;
}
.hot-search-tags {
  overflow: hidden;
  font-size: 26rpx;
  text-align: center;
  padding-bottom: 30rpx;
}
.history-search .title-text.history-line {
  position: relative;
  border-top: 2rpx solid #e1e1e1;
}
.search-display .title-text {
  padding: 30rpx 0;
  font-size: 30rpx;
  color: #666;
}
.clear-history image {
  width: 32rpx;
  height: 32rpx;
  position: absolute;
  right: 10rpx;
  top: 30rpx;
}
image {
  width: 320px;
  height: 240px;
  display: inline-block;
  overflow: hidden;
}
view {
  display: block;
}
* {
  margin: 0;
}
.history-search .his-search-tags {
  overflow: hidden;
  font-size: 26rpx;
  text-align: center;
  display: inline-block;
}
.history-search .his-search-tags .tags {
  max-width: 300rpx;
  overflow: hidden;
  float: left;
  border-radius: 50rpx;
  white-space: nowrap;
  text-overflow: ellipsis;
  background-color: #f2f2f2;
  box-sizing: border-box;
  margin-right: 20rpx;
  margin-bottom: 20rpx;
  padding: 10rpx 30rpx;
}
</style>


